<?php

$menuIndex = 0 ;

class CategoryList{
	var $sortSql ;
	var $itemSql ;
	var $sortSize = 10 ;
	var $itemSize = 6 ;
	var $itemCols = 2 ;
	var $itemImg = "";
	var $sortLinkUrl ;
	var $itemLinkUrl ;
	var $width = 220 ;

	function CategoryList(){
		
	}

	function setSortSql($sql){
		$this->sortSql = $sql ;
	}

	function setItemSql($sql){
		$this->itemSql = $sql ;
	}

	function setItemImg($img){
		$this->itemImg = $img ;
	}

	function getSortLinkUrl($url){
		$this->sortLinkUrl = $url ;
	}

	function getItemLinkUrl($url){
		$this->itemLinkUrl = $url ;
	}

	function setWidth($w){
		$this->width = $w ;
	}

	function printHTML(){
		print($this->getHTML());
	}

	function getHTML(){
		if($this->sortSql == ""){
			return "";
		}

		$html = "";

		$girl = new gridBean();
		$girl->init($this->itemSql,1,1000);

		$gridbean = new gridBean();
		$gridbean->init($this->sortSql,1,$this->sortSize);

		
		for($i=0;$i<$gridbean->getFetchRows();$i++){
			$id = $gridbean->getCol($i,0);
			$mc = $gridbean->getCol($i,1);

			$html .= "<table style='width:". $this->width ."px;margin-bottom:10px;'>";
			$html .= "<tr>";
			$html .= "	<td colspan='". $this->itemCols ."'><div style='width:100%;text-align:center;height:22px;'>[". $mc ."]</div></td>";
			$html .= "</tr>";


			$index = 0 ;
			for($n=0;$n<$girl->getFetchRows();$n++){
				if($girl->getCol($n,1) != $id){
					continue ;
				}
				if($index % $this->itemCols == 0){
					if($index > 0){
						$html .= "</tr>";
					}
					$html .= "<tr>";
				}

				$html .= "	<td style='width:" . (100/$this->itemCols) . "%;'>";
				
				if($this->itemImg != ""){
					$html .= "		<img src='". $this->itemImg ."'></img> ";
				}
				$html .= "			<a href='". $this->itemLinkUrl ."?button_". $girl->getFieldName(0) ."=". $girl->getCol($n,0) ."'>";
				$html .=			$girl->getCol($n,2);
				$html .= "			</a>";

				$html .= "	</td>";

				if($index >= $this->itemSize){
					break ;
				}

				$index++ ;
			}
			$temp = $index % $this->itemCols ;
			if($temp != 0){
				for($j=0; $j<($this->itemCols - $temp); $j++){
					$html .= "<td></td>";
				}
			}
			$html .= "</tr>";
			$html .= "</table>";
			
		}
		
		unset($girl);
		unset($gridbean);

		return $html ;		
	}

}

?>